<script setup>
import { ref, onMounted } from 'vue';
import { getHot } from '@/api/home.js';

const hotList = ref([]);

const getHotList = async () => {
  const res = await getHot();
  hotList.value = res.data.result;
};

onMounted(() => {
  getHotList();
});
</script>

<template>
  <div>
    <home-panel title="手机推荐" subTitle="新品上市 快来抢购">
      <ul class="goods-list">
        <li v-for="item in hotList" :key="item.id" class="goods-item">
          <RouterLink :to="`/detail/${item.id}`">
            <img :src="item.picture" :alt="item.alt" class="goods-image" />
            <p class="name">{{ item.title }}</p>
            <p class="desc">{{ item.alt }}</p>
          </RouterLink>
        </li>
      </ul>
    </home-panel>
  </div>
</template>

<style scoped lang="scss">
.goods-list {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: center;
  padding: 30px 0;
}

.goods-item {
  width: 300px;
  background: #f0f9f4;
  transition: all 0.3s ease;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);

  &:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
  }

  .goods-image {
    width: 100%;
    height: 250px;
    object-fit: cover;
  }

  .name, .desc {
    font-size: 16px;
    text-align: center;
    margin: 10px 0;
    padding: 0 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .desc {
    color: #555;
    font-size: 14px;
  }
}
</style>
